package com.test;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Vector;

public class Recorder {

	private static FileWriter fw = null;
	private static BufferedWriter bw = null;
	private static FileReader fr=null;
	private static BufferedReader br=null;
	
	private Vector<EnemyTank> ets=new Vector<EnemyTank>();
	private static Vector<Point> pts=new Vector<Point>();
	

	

	public void keepRecord() {

		try {

			fw = new FileWriter("d:\\myRecord.txt");
			bw = new BufferedWriter(fw);
			
			
			for(int i=0;i<ets.size();i++) {
				EnemyTank et = ets.get(i);
				
				if(et.isAlive()) {
					String location=et.getX() +" " + et.getY()+" " + et.getDirect();
					bw.write(location+"\r\n");
				}
			}
			
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		} finally {
			try {
				bw.close();
				fw.close();
			} catch (Exception e2) {
				// TODO: handle exception
				e2.printStackTrace();
			}
		}
	}
	
	public void getRecord() {
		try {
			fr=new FileReader("d:\\myRecord.txt");
			br=new BufferedReader(fr);
			//String n = br.readLine();
			String n ="";
			while((n=br.readLine())!=null) {
				String []res = n.split(" ");
				
					Point point=new Point(Integer.parseInt(res[0]), Integer.parseInt(res[1]),Integer.parseInt(res[2]));
					pts.add(point);
			}
			
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}finally {
			try {
				br.close();
				fr.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		}
	}
	public boolean isExist() {
		  File file = new File("d:\\myRecord.txt");
		  
		  if (!file.exists()) {
		   return false;
		  }else {
			return true;
		  }
		 }
	
	
	public Vector<EnemyTank> getEts() {
		return ets;
	}

	public void setEts(Vector<EnemyTank> ets) {
		this.ets = ets;
	}
	
	public Vector<Point> getPts() {
		return pts;
	}

	public static void setPts(Vector<Point> pts) {
		Recorder.pts = pts;
	}
}

class Point{
	int x;
	public int getX() {
		return x;
	}
	public void setX(int x) {
		this.x = x;
	}
	public int getY() {
		return y;
	}
	public void setY(int y) {
		this.y = y;
	}
	public int getDirect() {
		return direct;
	}
	public void setDirect(int direct) {
		this.direct = direct;
	}
	int y;
	int direct;
	public Point(int x, int y, int direct) {
		this.x = x;
		this.y = y;
		this.direct = direct;
	}
	
	
}